/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerBeans;

import entities.Event;
import entities.SeminarStatus;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import sessionBeans.EventFacade;
import sessionBeans.SeminarStatusFacade;

/**
 *
 * @author thuyhtp_b00491
 */
@ManagedBean
@RequestScoped
public class EventManager {

    @EJB
    private SeminarStatusFacade seminarStatusFacade;
    @EJB
    private EventFacade eventFacade;

    /** Creates a new instance of EventManager */
    public EventManager() {
    }
    private Integer id;
    private String name;
    private String intro;
    private String topic;
    private String speakerOrGuest;
    private Date starttime;
    private Date createtime;
    private float price;
    private String applyProcedure;
    private String requirement;
    private String address;
    private String term;
    private String note;
    private String image;
    private int seminarStatus;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getSpeakerOrGuest() {
        return speakerOrGuest;
    }

    public void setSpeakerOrGuest(String speakerOrGuest) {
        this.speakerOrGuest = speakerOrGuest;
    }

    public Date getStarttime() {
        return starttime;
    }

    public void setStarttime(Date starttime) {
        this.starttime = starttime;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

    public String getApplyProcedure() {
        return applyProcedure;
    }

    public void setApplyProcedure(String applyProcedure) {
        this.applyProcedure = applyProcedure;
    }

    public String getRequirement() {
        return requirement;
    }

    public void setRequirement(String requirement) {
        this.requirement = requirement;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTerm() {
        return term;
    }

    public void setTerm(String term) {
        this.term = term;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public int getSeminarStatus() {
        return seminarStatus;
    }

    public void setSeminarStatus(int seminarStatus) {
        this.seminarStatus = seminarStatus;
    }

    public void insertEvent() {
        try {
            SeminarStatus s = seminarStatusFacade.find(seminarStatus);
            createtime = new Date();
            Event event = new Event(name, intro, topic, speakerOrGuest, starttime, createtime, price, applyProcedure, requirement, address, term, note, image, s);
            eventFacade.create(event);
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Insert Success", "Event name : " + name));
            reset();
        } catch (Exception e) {
            e.printStackTrace();
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", e.getMessage()));
        }
    }
    private List<SeminarStatus> listSta;

    public List<SeminarStatus> getListSta() {
        listSta = seminarStatusFacade.findAll();
        return listSta;
    }

    public void setListSta(ArrayList<SeminarStatus> listSta) {
        this.listSta = listSta;
    }

    private void reset() {
        name = "";
        intro = "";
        topic = "";
        speakerOrGuest = "";
        starttime = new Date();
        createtime = new Date();
        price = 0;
        applyProcedure = "";
        requirement = "";
        address = "";
        term = "";
        note = "";
        image = "";
        seminarStatus = 1;
    }
}
